package chapters15_bingfa.chapters15_3;

/**
 * Created by xinxuchu on 2020/1/29.
 *
 * 等待结束，本质还是因为每个线程join太麻烦太占资源,换计数器的方式
 *
 */
public class MyLanch  {

    private int count;

    public MyLanch(int count) {
        this.count = count;
    }

    public synchronized void await() throws InterruptedException{
        while (count>0){
            wait();
        }
    }

    public synchronized void countDown(){
        count-- ;
        if (count<=0){
            notifyAll();
            System.out.println("解放啦");
        }

    }

}
